package com.atguigu.lease.web.admin.controller.apartment;


import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.PaymentType;
import com.atguigu.lease.web.admin.service.PaymentTypeService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Tag(name = "支付方式管理")
@RequestMapping("/admin/payment")
@RestController
public class PaymentTypeController {

    @Autowired
    private PaymentTypeService service;

    @Operation(summary = "查询全部支付方式列表")
    @GetMapping("list")
    public Result<List<PaymentType>> listPaymentType() {
/*      过滤条件构造器，这里是过滤逻辑删除是否返回，
        也可以加注解@TableLogic解决，或者在yml文件中配置
        mybatis-plus:
            global-config:
            db-config:
                logic-delete-field: flag # 全局逻辑删除的实体字段名(配置后可以忽略不配置步骤二)
                logic-delete-value: 1 # 逻辑已删除值(默认为 1)
                logic-not-delete-value: 0 # 逻辑未删除值(默认为 0)

        LambdaQueryWrapper<PaymentType> lqw = new LambdaQueryWrapper<>();
        lqw.eq(PaymentType::getIsDeleted,0);
        List<PaymentType> list = service.list(lqw);*/
        List<PaymentType> list = service.list();
        return Result.ok(list);
    }

    @Operation(summary = "保存或更新支付方式")
    @PostMapping("saveOrUpdate")
    public Result saveOrUpdatePaymentType(@RequestBody PaymentType paymentType) {
        service.saveOrUpdate(paymentType);
        return Result.ok();
    }

    @Operation(summary = "根据ID删除支付方式")
    @DeleteMapping("deleteById")
    public Result deletePaymentById(@RequestParam Long id) {
        service.removeById(id);
        return Result.ok();
    }

}















